<template>
	<view class="content" :style="{ height: windowHeight + 'px' }">
		<view class="view">
			<scroll-view @scrolltolower="lowerBottom" class="box_scroll" scroll-y="true" refresher-enabled="true"
				:refresher-triggered="triggered" :refresher-threshold="50" refresher-background="#f8f8f8"
				@refresherrefresh="onRefresh" @refresherrestore="onRestore">

				<view class="items line" v-for="(item, index) in list" :key="index">
					<view class="left">
						<view class="type">
							[ {{ item.name }} ]
						</view>
						<view class="title">
							{{ item.title }}
						</view>
						<view class="num">
							{{ item.startTime }}
						</view>
					</view>
					<view class="right">
						<view class="right_date">
							{{ item.status == '0' ? '未答题' : item.status == '1' ? ('比赛结果: 打分中') : ('比赛结果: 已打分') }}
						</view>
						<view class="right_pre" @click="goto(item)" v-if="item.status == '2'">
							查看详情
						</view>
					</view>
				</view>

				<view class="zanwu" v-if="list.length == 0">暂无数据</view>
				<u-loadmore v-if="list.length != 0" fontSize="25" :status="status" />

			</scroll-view>
		</view>
	</view>
</template>

<script>
import {
	systemInfo
} from '../../utils/mixin'
import { competitionjoined } from '@/api/index.js'
export default {
	components: {},
	mixins: [systemInfo],
	data() {
		return {
			list: [
			],

			queryParams: {
				pageNum: 1,
				pageSize: 10,
			},
			status: 'loadmore',
			triggered: false,
			downRefresh: false,
			pageCount: 0,
		}
	},
	onLoad() {
		// 状态栏高度
		this.getSystemInfo();

		this.triggered = true;
		this.downRefresh = true
		this.queryParams.pageNum = 1
		this.list = []
		this.getcollectList()
	},
	methods: {
		async getcollectList() {
			const res = await competitionjoined({ ...this.queryParams })
			this.pageCount = res.total
			res.rows.forEach(element => {
				element.startTime = element.startTime.split(' ')[0].replace(/-/g, "/")
			});
			//停止加载中
			this.triggered = false;
			this.downRefresh = false
			//处理完逻辑停止刷新
			uni.stopPullDownRefresh();
			if (this.list.length >= this.pageCount) {
				this.status = 'nomore';
			} else {
				let arr = [...this.list, ...res.rows]
				this.list = arr
				if (res.rows.length < 10) {
					this.status = 'nomore';
				}
			}
		},

		//触底加载
		lowerBottom() {
			if (this.queryParams.pageNum < this.pageCount) {
				if (!this.downRefresh) {
					this.downRefresh = true
					this.status = 'loading';
					this.queryParams.pageNum += 1
					this.getcollectList()
				}
			}
		},
		onRefresh() {
			this.triggered = true;
			this.downRefresh = true
			this.queryParams.pageNum = 1
			this.list = []
			this.getcollectList()
		},
		onRestore() {
			this.triggered = false; // 需要重置
		},


		goto(item) {
			uni.navigateTo({
				url: "/subpackage3/competition/competitionDetail?title=" + item.title + '&id=' + item.id
			})
		}
	}
}
</script>

<style lang="less" scoped>
.content {
	background-color: rgb(245, 245, 245);
	width: 100%;
	box-sizing: border-box;

	.red {
		color: red;
	}

	.line {
		border-bottom: 1px solid rgba(179, 173, 173, 0.2);
	}

	.view {
		width: calc(100% - 60rpx);
		height: calc(100% - 60rpx);
		margin-top: 30rpx;
		box-sizing: border-box;
		padding: 30rpx;
		background-color: #fff;
		position: relative;
		top: 30rpx;
		margin: auto;
		overflow: auto;
		border-radius: 15px;

		.zanwu {
			font-size: 30rpx;
			color: #b3adad;
			text-align: center;
			margin-top: 20px;
		}


		.box_scroll {
			height: 100%;
		}

		.items {
			padding: 30rpx 0;
			width: 100%;
			box-sizing: border-box;

			.center {
				color: red;
			}

			.left {
				width: 100%;
				display: flex;
				align-items: flex-start;
				font-size: 26rpx;

				.num {
					color: rgb(179, 173, 173);
				}

				.title {
					flex: 1;
					display: -webkit-box;
					/* 使用Webkit的弹性盒子模型 */
					-webkit-line-clamp: 2;
					/* 设置显示的行数 */
					-webkit-box-orient: vertical;
					/* 垂直排列子元素 */
					overflow: hidden;
					/* 隐藏溢出的内容 */
					text-overflow: ellipsis;
					/* 显示省略号 */
					margin-left: 10rpx;
				}

				.titles {
					flex: 1;
					margin-left: 10rpx;
				}
			}

			.right {
				color: rgb(179, 173, 173);
				font-size: 22rpx;
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

		}
	}
}
</style>